/*
 * Daniel R Padilla
 *
 * Copyright (c) 2007, Daniel R Padilla
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.databasefacade.table.system;


import org.databasefacade.DatabaseHelper;
import org.databasefacade.table.ConstraintKey;
import org.databasefacade.table.Table;
import org.databasefacade.table.column.Column;
import org.databasefacade.table.column.datatype.BooleanDataType;
import org.databasefacade.table.column.datatype.IntegerDataType;
import org.databasefacade.table.column.datatype.StringDataType;



public class DbfFieldRegistryTable extends Table {   
    public final static String DB_TABLE_NAME = "DBF_FIELD_REGISTRY";
    public final static String DB_TABLE_PRIMARY_KEY = DB_TABLE_NAME + "_KEY";
    public final static String FIELD_NAME = "FIELD_NAME";
    public final static String IS_PRIMARY_KEY = "IS_PRIMARY_KEY";
    public final static String IS_FOREIGN_KEY = "IS_FOREIGN_KEY";
    public final static String IS_REQUIRED = "IS_REQUIRED";
    public final static String IS_UNIQUE = "IS_UNIQUE";
    public final static String IS_UPDATABLE = "IS_UPDATABLE";
    
    public DbfFieldRegistryTable(DatabaseHelper helper) {
        super(helper, DB_TABLE_NAME);
        setIsConfigTable(true);
        
        // Foreign key to the table entry
        Column col = new Column(
        					this, 
        					DbfTableRegistryTable.DB_TABLE_PRIMARY_KEY,
        					new IntegerDataType(helper.getTranslator()));
        ConstraintKey fk1 = new ConstraintKey(col,
        		      DbfTableRegistryTable.DB_TABLE_NAME,
        		      DbfTableRegistryTable.DB_TABLE_PRIMARY_KEY);
        addForeignKey(fk1);
        addColumn(col);
        
        // Field Name
        col = new Column(this, FIELD_NAME, new StringDataType(helper.getTranslator(), 128));
        addColumn(col);
                 
        // Flags
        col = new Column(this, IS_PRIMARY_KEY, new BooleanDataType(helper.getTranslator()));
        addColumn(col);
        
        col = new Column(this, IS_FOREIGN_KEY, new BooleanDataType(helper.getTranslator()));
        addColumn(col);
        
        col = new Column(this, IS_REQUIRED, new BooleanDataType(helper.getTranslator()));
        addColumn(col);
        
        col = new Column(this, IS_UNIQUE, new BooleanDataType(helper.getTranslator()));
        addColumn(col);
        
        col = new Column(this, IS_UPDATABLE, new BooleanDataType(helper.getTranslator()));
        addColumn(col);
        
       
        Column cr = this.getColumn(FIELD_NAME);
        cr.getDatabaseMetaData().setIsRequired(true);
    }
}
